<template>
  <div>
    <h1>登录</h1>
    <van-field label="账号" v-model="form.username"></van-field>
    <van-field label="密码" v-model="form.password"></van-field>
    <van-button @click="login">登录</van-button>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: "login",
  data() {
    return {
      form: {}
    }
  },
  methods: {
    login() {
      axios.post('http://localhost:5000/login', this.form).then(res => {
        if (res.data.code == 200) {
          alert('登录成功')
          localStorage.setItem('userid', res.data.userid)
          localStorage.setItem('ksname', res.data.ksname)
          this.$router.push('/index')
        } else {
          alert(res.data.mes)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>